<template>
  <div class="app-container">
    <el-form
      :model="config"
      :rules="rules"
      ref="config"
      label-position="right"
      label-width="120px" style="margin-left:30px;"
    >
      <div>
        <span>用户下单使用积分时换算成人民币的比例，如填100表示100个积分当做1元钱使用。</span>
        <el-divider></el-divider>
      </div>
      <el-form-item label="积分换算比例" prop="integralScale">
        <el-input-number v-model="config.integralScale" :min="1" :max="999999999" :precision="0"></el-input-number>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('config')">立即提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { configIntegral, configUpdateIntegral} from '@/api/member'
export default {
  name: "configedit",
  config: {},
  data() {
    return {
      config: {},
      rules: {
        integralScale: [{ required: true, message: '请填写积分数量', trigger: 'blur' }]
      },
    };
  },
  created() {
    configIntegral().then((res) => {
      this.config = res.data.data.config
    })
  },
  methods: {
    submitForm(config) {
      this.$refs[config].validate((valid) => {
        if (valid) {
          configUpdateIntegral(this.config).then(res => {
            if(!res.data.success) {
              Message.error(res.data.message);
              return;
            }
            Message.success('操作成功')
            return;
          })
        }
      });
    }
  }

}
</script>

<style>
</style>
